<?php
include("header.php");
if (empty($_GET['action'])) {
    $sql = "SELECT Text FROM texte WHERE Name = '" . $_GET['textfile'] . "' LIMIT 1";
    $sql_query = mysql_query($sql);
    $sql_result = mysql_fetch_assoc($sql_query);
    $update_text = $sql_result['Text'];
    ?>
        <div class="main_clear_box_content">
            <form method="post" action="?action=update_txt&textfile=<?php print $_GET['textfile']; ?>" onsubmit="document.getElementById('save_button').disabled='true';">
                <textarea name="text" id="textfield" style="width:99%;height:340px;"><?php print html_entity_decode($update_text, ENT_QUOTES, 'UTF-8'); ?></textarea><br />
                <table class="edit_table" cellspacing="0" cellpadding="0">
                    <tr>
                        <td width="20%">
                            <input type="submit" value="Speichern" id="save_button" />
                        </td>
                        <td width="80%" align="right">
                            <img src="<?php print $url_page; ?>/images/editor/button_hr.gif" onclick="insert('textfield','[hr]')" onmouseover="this.style.padding='0';this.style.border='1px solid #000000'" onmouseout="this.style.padding='1px';this.style.border='0'" onmousedown="this.style.backgroundColor='#FF0000'" onmouseup="this.style.backgroundColor=''" style="padding:1px;border:0px" title="Trennlinie" />
                            <img src="<?php print $url_page; ?>/images/editor/button_bold.gif" onclick="hrcfett('textfield')" border="0" onmouseover="this.style.padding='0';this.style.border='1px solid #000000'" onmouseout="this.style.padding='1px';this.style.border='0'" onmousedown="this.style.backgroundColor='#FF0000'" onmouseup="this.style.backgroundColor=''" style="padding:1px;border:0px" title="Fett" />
                            <img src="<?php print $url_page; ?>/images/editor/button_italic.gif" onclick="hrckursiv('textfield')" border="0" onmouseover="this.style.padding='0';this.style.border='1px solid #000000'" onmouseout="this.style.padding='1px';this.style.border='0'" onmousedown="this.style.backgroundColor='#FF0000'" onmouseup="this.style.backgroundColor=''" style="padding:1px;border:0px" title="Kursiv" />
                            <img src="<?php print $url_page; ?>/images/editor/button_underline.gif" onclick="hrcul('textfield')" border="0" onmouseover="this.style.padding='0';this.style.border='1px solid #000000'" onmouseout="this.style.padding='1px';this.style.border='0'" onmousedown="this.style.backgroundColor='#FF0000'" onmouseup="this.style.backgroundColor=''" style="padding:1px;border:0px" title="Unterstrichen" />
                            <img src="<?php print $url_page; ?>/images/editor/button_center.gif" onclick="hrccen('textfield')" border="0" onmouseover="this.style.padding='0';this.style.border='1px solid #000000'" onmouseout="this.style.padding='1px';this.style.border='0'" onmousedown="this.style.backgroundColor='#FF0000'" onmouseup="this.style.backgroundColor=''" style="padding:1px;border:0px" title="Zentriert" />
                            <img src="<?php print $url_page; ?>/images/editor/toolbar_separator.gif">
                            <img src="<?php print $url_page; ?>/images/editor/button_image.gif" onclick="hrcimage('textfield')" border="0" onmouseover="this.style.margin='0';this.style.border='1px solid #000000'" onmouseout="this.style.margin='1px';this.style.border='0'" onmousedown="this.style.backgroundColor='#FF0000'" onmouseup="this.style.backgroundColor=''" style="margin:1px;border:0px" title="Bild einf&uuml;gen" />
                            <img src="<?php print $url_page; ?>/images/editor/button_link.gif" onclick="hrclink('textfield')" border="0" onmouseover="this.style.padding='0';this.style.border='1px solid #000000'" onmouseout="this.style.padding='1px';this.style.border='0'" onmousedown="this.style.backgroundColor='#FF0000'" onmouseup="this.style.backgroundColor=''" style="padding:1px;border:0px" title="Hyperlink einf&uuml;gen" />
                            <img src="<?php print $url_page; ?>/images/editor/button_mail.gif" onclick="hrcemail('textfield')" border="0" onmouseover="this.style.padding='0';this.style.border='1px solid #000000'" onmouseout="this.style.padding='1px';this.style.border='0'" onmousedown="this.style.backgroundColor='#FF0000'" onmouseup="this.style.backgroundColor=''" style="padding:1px;border:0px" title="E-Mail Link einf&uuml;gen" />
                        </td>
                    </tr>
                </table>
            </form>
        </div>
        <div class="main_border_box_right"></div>
        <div class="main_border_box_l_u"></div>
        <div class="main_border_box_bottom"></div>
        <div class="main_border_box_r_u"></div>
<?php
}
if ($_GET['action'] == "update_txt") {
    $sql = "INSERT INTO texte (Name, Text) VALUES ('" . $_GET['textfile'] . "', '" . htmlentities($_POST['text'], ENT_QUOTES, 'UTF-8') . "') ON DUPLICATE KEY UPDATE Text = '" . htmlentities($_POST['text'], ENT_QUOTES, 'UTF-8') . "'";
    $result = mysql_query($sql);
    if (mysql_affected_rows())
        header("location: " . $url_page . "/index.php?site=" . $_GET['textfile'] . "&update=true");
    else
        header("location: " . $url_page . "/index.php?site=" . $_GET['textfile'] . "&update=false");
}
include("footer.php");
?>